﻿/**
 * Peter
 * Created by: Peter Development Team
 *    http://peter.codeplex.com/
 * 
 * GNU General Public License version 2 (GPLv2)
 *    http://peter.codeplex.com/license
 *
 *  This code is provided on an AS IS basis, with no WARRANTIES,
 *  CONDITIONS or GUARANTEES of any kind.
 *  
 **/

namespace Peter.Logic.Dialogs
{
   /// <summary>
   /// Logic for opening an existing project.
   /// </summary>
   public class ModelOpenProject : ModelProjectBase
   {
      /// <summary>
      /// Initializes the model for opening a project.
      /// </summary>
      /// <param name="projectManager">The project manager.</param>
      public ModelOpenProject (ModelProjectManager projectManager)
         : base (projectManager)
      {
         this.Width = 350;
         this.Height = 400;
         this.OkButtonText = "Open";
      }

      /// <summary>
      /// Checks if the ok command can execute.
      /// </summary>
      /// <returns>If it is ok to execute.</returns>
      public override bool CanOkExecute ()
      {
         return this.SelectedItem != null &&
                this.SelectedLocation != null;
      }

      /// <summary>
      /// Occurs when the ok button on the dialog is pressed.
      /// </summary>
      public override void OkExecuted ()
      {
         var openProject = this.SelectedItem.Open (this.SelectedLocation.File.FullName);
         if (openProject != null)
         {
            this.ProjectManager.Workspace.Open (openProject);
            base.OkExecuted ();
         }
      }
   }
}
